﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCLCustomerManagement.BusinessLogic.Category;
using NCLCustomerManagement.DataAccess.CustomerRepository;
using NCLCustomerManagement.DataTransferObjects.Customer;

namespace NCLCustomerManagement.BusinessLogic.Customer
{
    public class CustomerBC : BaseBC, ICustomerBC
    {
        private ICustomerRepository _cateRepo;

        public CustomerBC(ICustomerRepository cateRepository)
        {
            _cateRepo = cateRepository;
        }


        public override My.DataAccess.Core.IBaseRepository<DTO> GetRepository<DTO>()
        {
            return _cateRepo as My.DataAccess.Core.IBaseRepository<DTO>;
        }

        public IEnumerable<CustomerDTO> GetCustomerList(int? regionId, int? productCategoryId, string customerPhone, bool isAdmin)
        {
            return _cateRepo.GetCustomersByCriteria(regionId, productCategoryId, customerPhone, isAdmin);
        }


        public IEnumerable<ProductCategoryDTO> GetAllCategories()
        {
            return _cateRepo.GetAllCategories();
        }


        public void DeleteCustomer(int[] items)
        {
            _cateRepo.DeleteCustomer(items);
        }


        public void AddNewCustomer(CustomerDTO dto)
        {
            _cateRepo.AddNewCustomer(dto);
        }


        public void UpdateCustomer(CustomerDTO dto)
        {
            _cateRepo.UpdateCustomer(dto);
        }


        public bool CheckProductExist(int productId, int customerId)
        {
            return _cateRepo.CheckProductExist(productId, customerId);
        }


        public void RequestChange(CustomerDTO dto, string requester, string requestTo)
        {
            _cateRepo.RequestChange(dto, requester, requestTo);
        }


        public bool CheckChange(CustomerDTO dto)
        {
            var customerInDb = _cateRepo.GetCustomerById(dto.Id);
            return !dto.Equals(customerInDb);
        }


        public CustomerDTO GetCustomerById(int id)
        {             
            return _cateRepo.GetCustomerById(id);
        }




        public void AddNewProductCategory(string name)
        {
            _cateRepo.AddNewProductCategory(name);
        }

        public void DeleteCategory(int[] ids)
        {
            foreach (var item in ids)
            {
                _cateRepo.DeleteProductCategory(item);
            }
        }


        public void UpdateProductCategory(int id, string name)
        {
            _cateRepo.UpdateProductCategory(id, name);
        }


        public IEnumerable<CustomerDTO> GetAllCustomers()
        {
            return _cateRepo.GetAll();
        }
    }
}
